/*
 * @Descripttion: 
 * @version: 
 * @Author: mmzhang
 * @Date: 2021-07-27 16:02:34
 * @LastEditTime: 2022-03-31 14:55:10
 */
let vm = null;
import poptipContent from "../components/poptipContent";
import CustomerMgr from '@/biz/customer/customerOpt.js'
import dt from "@dt/dt";
import table from '@/components/dt/table/render.js'
import nameOpt from '@/biz/option/name.js'

function columnField(_this) {
  let columns2 = {}
  columns2 = {
    customerName: {
      field: 'customerName',
      title: '客户姓名',
      minWidth: 120,
      fixed: 'left',
      header: {
        filter: {
          title: '客户姓名',
          key: 'customerName',
          placeholder: '请输入客户姓名',
          input: {}
        }
      }
    },
    customerPhone: {
      field: 'customerPhone',
      minWidth: 130,
      fixed: 'left',
      header: {
        filter: {
          title: '手机号码',
          key: 'customerPhone',
          placeholder: '请输入手机号码',
          input: {}
        }
      }
    },
    recommender: {
      field: 'recommender',
      minWidth: 180,
      header: {
        filter: nameOpt.createPushPeople({
          key: 'recommender',
          title: '推荐人',
          to: (info) => {
            return {
              recommender: info.workNo
            }
          }
        }, 'onCase')
      },
      slots: {
        default: (params, h) => {
          let recommender = []
          if (params.row.recommender) {
            recommender = params.row.recommender.split(',')
          }
          return table.cell.text(h, {
            value: recommender && recommender.length > 0 ? recommender
              .length > 1 ? `${recommender[0]}等${recommender.length}个` :
              recommender[0] : '-'
          })
        }
      }
    },

    attributionConsultant: {
      field: 'attributionConsultant',
      minWidth: 120,
      // fixed: 'left',
      header: {
        filter: {
          title: '归属顾问',
          key: 'userIds',
          placeholder: '请选择归属顾问',
          load: (o) => {
            o.select.options = CustomerMgr.consultants()
          },
          select: {
            options: [],
            multiple: true,
            filterable: true,
            remote: (key) => {
              return CustomerMgr.getConsultant(key)
            }
          }
        }
      },
    },

    status: {
      field: 'status',
      minWidth: 120,
      header: {
        filter: {
          title: '客户进度',
          key: 'status',
          placeholder: '请选择客户进度',
          load: (o) => {
            o.select.options = CustomerMgr.status()
          },
          select: {
            options: [],
            multiple: true,
            filterable: true,
          }
        }
      }
    },
    channelSource: {
      field: 'channelSource',
      minWidth: 160,
      header: {
        filter: {
          title: '来源渠道',
          key: 'channelSource',
          placeholder: '请选择来源渠道',
          load: (o) => {
            o.select.options = CustomerMgr.channelSource()
          },
          select: {
            options: [],
            multiple: true,
            filterable: true,
          }
        }
      }
    },
    intentionLevel: {
      field: 'intentionLevel',
      minWidth: 120,
      header: {
        filter: {
          title: '意向等级',
          key: 'intentionLevel',
          placeholder: '请选择意向等级',
          load: (o) => {
            o.select.options = CustomerMgr.intentionLevel()
          },
          select: {
            options: [],
            multiple: true,
            filterable: true,
          }
        }
      }
    },
    intentionPurpose: {
      field: 'intentionPurpose',
      minWidth: 160,
      header: {
        filter: {
          title: '置业目的',
          key: 'intentionPurpose',
          placeholder: '请选择置业目的',
          load: (o) => {
            o.select.options = CustomerMgr.intentionPurpose()
          },
          select: {
            options: [],
            multiple: true,
            filterable: true,
          }
        }
      }
    },
    intentionProduct: {
      field: 'intentionProduct',
      minWidth: 120,
      title: '意向业态',
      header: {
        filter: {
          title: '意向业态',
          key: 'intentionProduct',
          placeholder: '请选择意向业态',
          load: (o) => {
            o.select.options = CustomerMgr.intentionProduct()
          },
          select: {
            options: [],
            multiple: true,
            filterable: true,
          }
        }
      }
    },

    intentionHouseType: {
      field: 'intentionHouseType',
      minWidth: 160,
      header: {
        filter: {
          title: '意向户型',
          key: 'intentionHouseType',
          placeholder: '请选择意向户型',
          load: (o) => {
            o.select.options = CustomerMgr.intentionHouseType()
          },
          select: {
            options: [],
            multiple: true,
            filterable: true,
          }
        }
      }
    },
    intentionArea: {
      field: 'intentionArea',
      minWidth: 160,
      header: {
        filter: {
          title: '意向面积',
          key: 'intentionArea',
          placeholder: '请选择意向面积',
          load: (o) => {
            o.select.options = CustomerMgr.intentionArea()
          },
          select: {
            options: [],
            multiple: true,
            filterable: true,
          }
        }
      }
    },
    intentionTotalPrice: {
      field: 'intentionTotalPrice',
      minWidth: 160,
      header: {
        filter: {
          title: '意向总价',
          key: 'intentionTotalPrice',
          placeholder: '请选择意向总价',
          load: (o) => {
            o.select.options = CustomerMgr.intentionTotalPrice()
          },
          select: {
            options: [],
            multiple: true,
            filterable: true,
          }
        }
      }
    },
    intentionAveragePrice: {
      field: 'intentionAveragePrice',
      minWidth: 160,
      header: {
        filter: {
          title: '意向单价',
          key: 'intentionAveragePrice',
          placeholder: '请选择意向单价',
          load: (o) => {
            o.select.options = CustomerMgr.intentionAveragePrice()
          },
          select: {
            options: [],
            multiple: true,
            filterable: true,
          }
        }
      }
    },
    intentionRegion: {
      field: 'intentionRegion',
      minWidth: 140,
      header: {
        filter: {
          title: '意向区域',
          key: 'intentionRegion',
          placeholder: '请选择意向区域',
          load: (o) => {
            o.select.options = CustomerMgr.intentionRegion()
          },
          select: {
            options: [],
            multiple: true,
            filterable: true,
          }
        }
      }
    },
    //写死两个
    sourceType: {
      field: 'sourceType',
      minWidth: 120,
      header: {
        filter: {
          title: '创建方式',
          key: 'createMethod',
          placeholder: '请选择创建方式',
          select: {
            options: [
              { key: 1, value: '扫码授权' },
              { key: 2, value: '手动录入' },
              { key: 3, value: '网络来客' },
            ],
            multiple: true,
            filterable: true,
          }
        }
      }
    },
    checkInMethod: {
      field: 'checkInMethod',
      minWidth: 120,
      header: {
        filter: {
          title: '签到方式',
          key: 'checkInMethod',
          placeholder: '请选择签到方式',
          select: {
            options: [
              { key: 1, value: '扫码签到' },
              { key: 2, value: '手动签到' },
              { key: 3, value: '新增签到' },
            ],
            multiple: true,
            filterable: true,
          }
        }
      }
    },

    // 三个时间
    createTime: {
      field: 'createTime',
      minWidth: 160,
      header: {
        filter: {
          title: '创建日期',
          key: 'customerCreateStartTime',
          placeholder: '请选择创建日期',
          date: {
            type: 'daterange'
          },
          data: {
            from: (info) => {
              if (info.customerCreateStartTime && info.customerCreateEndTime) {
                return [info.customerCreateStartTime, info.customerCreateEndTime]
              }
              return null
            },
            to: (v) => {
              return {
                customerCreateStartTime: v[0],
                customerCreateEndTime: v[1],
              }
            }
          }
        }
      },
      cell: {
        value: (row) => row.createTime ? vm.$tool.dateFtt('yyyy/MM/dd hh:mm', row
          .createTime) : '',
        text: {}
      }
    },
    lastVisitTime: {
      field: 'lastVisitTime',
      minWidth: 160,
      header: {
        filter: {
          title: '最近到访时间',
          key: 'lastVisitStartTime',
          placeholder: '请选择最近到访时间',
          date: {
            type: 'daterange'
          },
          data: {
            from: (info) => {
              if (info.lastVisitStartTime && info.lastVisitEndTime) {
                return [info.lastVisitStartTime, info.lastVisitEndTime]
              }
              return null
            },
            to: (v) => {
              return {
                lastVisitStartTime: v[0],
                lastVisitEndTime: v[1],
              }
            }
          }
        }
      },
      cell: {
        value: (row) => row.lastVisitTime ? vm.$tool.dateFtt('yyyy/MM/dd hh:mm', row
          .lastVisitTime) : '',
        text: {}
      }
    },
    lastFollowUpTime: {
      field: 'lastFollowUpTime',
      minWidth: 160,
      header: {
        filter: {
          title: '最近跟进时间',
          key: 'lastFollowUpStartTime',
          placeholder: '请选择最近跟进时间',
          date: {
            type: 'daterange'
          },
          data: {
            from: (info) => {
              if (info.lastFollowUpStartTime && info.lastFollowUpEndTime) {
                return [info.lastFollowUpStartTime, info.lastFollowUpEndTime]
              }
              return null
            },
            to: (v) => {
              return {
                lastFollowUpStartTime: v[0],
                lastFollowUpEndTime: v[1],
              }
            }
          }
        }
      },
      cell: {
        value: (row) => row.lastFollowUpTime ? vm.$tool.dateFtt('yyyy/MM/dd hh:mm', row
          .lastFollowUpTime) : '',
        text: {}
      }
    },

    gender: {
      field: 'gender',
      title: '性别',
      minWidth: 80,
    },
    standbyPhone: {
      field: 'standbyPhone',
      title: '备用号码',
      minWidth: 160,
    },
    wechat: {
      field: 'wechat',
      title: '微信号',
      minWidth: 160,
    },
    telChangeVisit: {
      field: 'telChangeVisit',
      title: '是否电转访',
      minWidth: 110,
    },
    intentionSubway: {
      field: 'intentionSubway',
      title: '意向地铁',
      minWidth: 160,
    },
    intentionLoopLine: {
      field: 'intentionLoopLine',
      title: '意向环线',
      minWidth: 140,
    },
    downPaymentInterval: {
      title: '首付区间',
      field: 'downPaymentInterval',
      minWidth: 120,
    },
    paymentRatio: {
      title: '付款比例',
      field: 'paymentRatio',
      minWidth: 110,
    },
    attentionBuilding: {
      title: '关注楼栋',
      field: 'attentionBuilding',
      minWidth: 110,
    },
    attentionFloor: {
      title: '关注楼层',
      field: 'attentionFloor',
      minWidth: 120,
    },
    attentionFactor: {
      title: '关注因素',
      field: 'attentionFactor',
      minWidth: 160,
    },
    resistancePoints: {
      title: '抗性因素',
      field: 'resistancePoints',
      minWidth: 120,
    },
    numberVisiting: {
      title: '来访人数',
      field: 'numberVisiting',
      minWidth: 120,
    },
    visitorStructure: {
      title: '来访人员结构',
      field: 'visitorStructure',
      minWidth: 120,
    },
    hisFirstTime: {
      title: '首访时间',
      field: 'hisFirstTime',
      minWidth: 160,
      cell: {
        value: (row) => row.hisFirstTime ? vm.$tool.dateFtt('yyyy/MM/dd hh:mm', row
          .hisFirstTime) : '',
        text: {}
      }
    },
    receptionTime: {
      title: '接待时长',
      field: 'receptionTime',
      minWidth: 120,
    },
    ageRange: {
      title: '客户年龄',
      field: 'ageRange',
      minWidth: 120,
    },
    purchaseIntegral: {
      title: '购房积分',
      field: 'purchaseIntegral',
      minWidth: 120,
    },
    paymentType: {
      title: '付款方式',
      field: 'paymentType',
      minWidth: 120,
      cell: {
        value: (row) => { return dt.dictInfo().__value('paymentType', row.paymentType) },
        text: {}
      }
    },
    historyMarriage: {
      title: '近期婚史',
      field: 'historyMarriage',
      minWidth: 120,
    },
    census: {
      title: '户籍',
      field: 'census',
      minWidth: 120,
    },
    buyHouseQualification: {
      title: '购房资质',
      field: 'buyHouseQualification',
      minWidth: 120,
    },
    loansQualification: {
      title: '贷款资质',
      field: 'loansQualification',
      minWidth: 120,
    },
    familyStructure: {
      title: '家庭结构',
      field: 'familyStructure',
      minWidth: 120,
    },
    livingArea: {
      title: '居住区域',
      field: 'livingArea',
      minWidth: 120,
    },
    workingArea: {
      title: '工作区域',
      field: 'workingArea',
      minWidth: 120,
    },
    vehicle: {
      title: '交通工具',
      field: 'vehicle',
      minWidth: 120,
    },
    industry: {
      title: '从事行业',
      field: 'industry',
      minWidth: 120,
    },
    position: {
      field: 'position',
      title: '职务职位',
      minWidth: 120,
    },
    educationBackground: {
      field: 'educationBackground',
      title: '学历',
      minWidth: 120,
    },
    capitalSource: {
      field: 'capitalSource',
      title: '资金来源',
      minWidth: 120,
    },
    keyDecisionMaker: {
      field: 'keyDecisionMaker',
      title: '决策关键人',
      minWidth: 120,
    },
    houseNum: {
      field: 'houseNum',
      title: '现有房产套数',
      minWidth: 140,
    },
    customerFeature: {
      title: '客户特征',
      field: 'customerFeature',
      minWidth: 200,
    },
    workUnit: {
      title: '工作单位',
      field: 'workUnit',
      minWidth: 110,
    },
    workUnit: {
      title: '工作单位',
      field: 'workUnit',
      minWidth: 110,
    },
    annualIncome: {
      title: '年收入',
      field: 'annualIncome',
      minWidth: 110,
    },
    nowLiveHouse: {
      title: '居住小区',
      field: 'nowLiveHouse',
      minWidth: 110,
    },
    homeCount: {
      title: '置业次数',
      field: 'homeCount',
      minWidth: 110,
    },
    visitCount: {
      title: '来访次数',
      field: 'visitCount',
      minWidth: 110,
    },
    demandLand: {
      title: '需求地段',
      field: 'demandLand',
      minWidth: 110,
    },
    cognitiveChannel: {
      title: '认知途径',
      field: 'cognitiveChannel',
      minWidth: 110,
    },
    competitorArea: {
      title: '竞品区域',
      field: 'competitorArea',
      minWidth: 110,
    },
    competitorCommunity: {
      title: '竞品小区',
      field: 'competitorCommunity',
      minWidth: 110,
    },
    homeOwnershipPlanTime: {
      title: '计划置业时间',
      field: 'homeOwnershipPlanTime',
      minWidth: 110,
    },
    isCapitalVerification: {
      title: '是否验资',
      field: 'isCapitalVerification',
      minWidth: 110,
    },
    isUpgradeCapitalVerification: {
      title: '是否升级验资',
      field: 'isUpgradeCapitalVerification',
      minWidth: 110,
    },

    featurePhoto: {
      // title: '附件特征',
      // field: 'featurePhoto',
      // minWidth: 110,


      field: 'featurePhoto',
      minWidth: 140,
      title: '特征附件',
      slots: {
        default: (params, h) => {
          let img = {
            event: 'lookImg',
            src: params.row.featurePhoto[0] ? params.row.featurePhoto[0] : '',
            data: params.row.featurePhoto
          }
          // return table.cell.img(_this, h, img, true)
          return params.row.featurePhoto?table.cell.img(_this, h, img, true):'-'
        }

      }
    },

  }
  return columns2
}

function columns(head, _this) {
  let fields = columnField(_this),
    data = []
  for (let item of head) {
    data.push(fields[item.field] || item)
  }
  return data
}

function options(_this, head) {
  vm = _this
  return [
    {
      type: 'checkbox',
      width: 60,
      align: 'center',
      fixed: 'left'
    },
    ...columns(head, _this)
  ]
}

export default {
  options
}